<template>
    <div>
<!--        面包屑导航-->
        <bread-nav>
            <span slot="nav1">订单管理</span>
            <span slot="nav2">订单列表</span>
        </bread-nav>
<!--        卡片视图-->
        <el-card>
            <el-input placeholder="请输入内容" v-model="queryInfo.query" @change="searchUser"
                      clearable style="width: 300px">
                <template slot="append">
                    <el-button slot="append" icon="el-icon-search" @click="searchUser"></el-button>
                </template>
            </el-input>
            <el-table
                    :data="orderForm"
                    stripe
                    border
                    style="width: 100%">
                <el-table-column
                        type="index"
                        label="#">
                </el-table-column>
                <el-table-column
                        prop="order_number"
                        label="订单编号"
                        width="220px">
                </el-table-column>
                <el-table-column
                        prop="order_price"
                        label="订单价格"
                        width="180">
                </el-table-column>
                <el-table-column
                        prop="order_pay"
                        label="是否付款">
                    <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.row.order_pay === '1'">支付宝</el-tag>
                        <el-tag type="success" v-if="scope.row.order_pay === '2'">微信</el-tag>
                        <el-tag type="success" v-if="scope.row.order_pay === '3'">银行卡</el-tag>
                        <el-tag type="warning" v-if="scope.row.order_pay === '0'">未付款</el-tag>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="is_send"
                        label="是否发货">
                </el-table-column>
                <el-table-column
                        prop="create_time"
                        width="200px"
                        label="下单时间">
                    <template slot-scope="scope">
                        {{scope.row.create_time | dateFormat}}
                    </template>
                </el-table-column>
                <el-table-column
                        prop="address"
                        label="操作"
                        width="180px">
                    <template slot-scope="scope">
                        <el-button type="primary" icon="el-icon-edit" @click="editOrder(scope.row)"
                        size="mini"></el-button>
                        <el-button type="success" icon="el-icon-position" size="mini" @click="progressDia"></el-button>
                    </template>
                </el-table-column>
            </el-table>
<!--            分页-->
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="queryInfo.pagenum"
                    :page-sizes="[5, 10, 15, 20]"
                    :page-size="queryInfo.pagesize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </el-card>
<!--        修改订单信息对话框-->
        <edit-order-dia :message="editVisible"/>
        <progress-dia :message="progressVisible"/>
    </div>
</template>

<script>
    import BreadNav from "../../components/content/BreadNav";
    import EditOrderDia from "./orderComp/EditOrderDia";
    import ProgressDia from "./orderComp/ProgressDia";
    import {getOrderInfo} from "../../network/order";
    export default {
        name: "Order",
        components:{
            BreadNav,
            EditOrderDia,
            ProgressDia
        },
        data(){
            return {
                queryInfo:{
                    query:'',
                    pagenum:1,
                    pagesize:5
                },
                orderForm:[],
                total:0,
                editVisible:false,
                progressVisible:false,
            }
        },
        methods:{
            //获取订单数据列表
            getOrder(){
                getOrderInfo(this.queryInfo).then(res => {
                    if (res.data.meta.status !== 200){
                        this.$message.error(res.data.meta.msg)
                    }
                    this.orderForm = res.data.data.goods;
                    this.total = res.data.data.total
                    }
                )
            },
            //搜索订单
            searchUser(){
                this.getOrder()
            },
            //修改当前页显示条数
            handleSizeChange(val){
                this.queryInfo.pagesize = val;
                this.getOrder()
            },
            //修改当前页
            handleCurrentChange(val){
                this.queryInfo.pagenum = val;
                this.getOrder()
            },
            //编辑订单信息
            editOrder(row){
                console.log(row);
                this.editVisible = !this.editVisible
            },
            progressDia(){
                this.progressVisible = !this.progressVisible
            }
        },
        mounted() {
            this.getOrder()
        },
        created() {
            this.$bus.$on('editOrder',() => {this.editVisible = !this.editVisible});
            this.$bus.$on('progressOrder',() => {this.progressVisible = !this.progressVisible});
        }
    }
</script>

<style scoped lang="less">
    .el-table{
        margin-top: 1rem;
    }

</style>